package com.qfjy.homework.zhangzheng;

import java.util.ArrayList;
import java.util.List;

/** 张三实现类
 * @date: 2022/6/30 0:39
 * @version: 1.0
 */
public class ZhangSan implements Debit {

    private List<Credit> allCredit =new ArrayList<>();
    private Integer state;//0无钱；1有钱

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    @Override
    public void borrow(Credit credit) {
        //添加一个观察者对象
        allCredit.add(credit);
    }

    @Override
    public void notifyAllObservers() {
        for (Credit credit : allCredit) {
            credit.takeMoney();
        }
        //allCredit.forEach(credit -> credit.takeMoney());
    }
}
